package com.lyh.societiesmanager.controller;

import com.lyh.societiesmanager.ClubService.ActivityService;
import com.lyh.societiesmanager.entity.Activity;
import com.lyh.societiesmanager.entity.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/activities")
@Api(tags = "活动管理接口")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    @ApiOperation("查询所有活动")
    @GetMapping
    public Response<List<Activity>> getAllActivities() {
        return Response.success(activityService.list());
    }

    @ApiOperation("根据ID查询活动")
    @GetMapping("/{id}")
    public Response<Activity> getActivityById(@PathVariable Integer id) {
        Activity activity = activityService.getById(id);
        return activity != null ? Response.success(activity) : Response.error(404, "未找到该活动");
    }

    @ApiOperation("新增活动")
    @PostMapping
    public Response<Boolean> addActivity(@RequestBody Activity activity) {
        return activityService.save(activity) ? Response.success("添加成功", true) : Response.error(500, "添加失败");
    }

    @ApiOperation("更新活动信息")
    @PutMapping("/{id}")
    public Response<Boolean> updateActivity(@PathVariable Integer id, @RequestBody Activity activity) {
        activity.setActivityId(id);
        return activityService.updateById(activity) ? Response.success("更新成功", true) : Response.error(500, "更新失败");
    }

    @ApiOperation("删除活动")
    @DeleteMapping("/{id}")
    public Response<Boolean> deleteActivity(@PathVariable Integer id) {
        return activityService.removeById(id) ? Response.success("删除成功", true) : Response.error(500, "删除失败");
    }
}